const path = require('path');
const defaultSettings = require('./src/utils/settings.js');

function resolve(dir) {
    return path.join(__dirname, dir)
}

const name = defaultSettings.title || '' ;// page title

module.exports = {
    pluginOptions : {
        electronBuilder: {
            externals: ['serialport'],
            nodeIntegration: true,
            nodeModulesPath: ['../../node_modules', './node_modules'],
            buildDependenciesFromSource: true,
            npmRebuild: true,
            // afterSign: "./notarize.js",
            builderOptions: {
                "appId": "plus.smartdevice.shortUrl",
                "productName": "shortUrl", //项目名，也是生成的安装文件名，即demo.exe
                "copyright": "Copyright © 2025", //版权信息
                "asar": true,
                "compression": "maximum",
                "publish": [
                    {
                        "provider": "generic",
                        "url": "https://home.smartdevice.plus/release/shortUrl",
                    }
                ],
                "dmg": {
                    "contents": [{
                            "x": 410,
                            "y": 150,
                            "type": "link",
                            "path": "/Applications"
                        },
                        {
                            "x": 130,
                            "y": 150,
                            "type": "file"
                        }
                    ]
                },
                "nsis": {
                    "oneClick": false, // 是否一键安装
                    "allowElevation": true, // 允许请求提升。 如果为false，则用户必须使用提升的权限重新启动安装程序。
                    "allowToChangeInstallationDirectory": true, // 允许修改安装目录
                    "installerIcon": "./public/favicon.ico", // 安装图标
                    "uninstallerIcon": "./public/favicon.ico", //卸载图标
                    "installerHeaderIcon": "./public/favicon.ico", // 安装时头部图标
                    "createDesktopShortcut": true, // 创建桌面图标
                    "createStartMenuShortcut": true, // 创建开始菜单图标
                    "shortcutName": "shortUrl", // 图标名称
                    "deleteAppDataOnUninstall": true,
                },
                "win": { //win相关配置
                    "icon": "./public/favicon.ico", //图标，当前图标在根目录下，注意这里有两个坑
                    "target": [{
                        "target": "nsis", //利用nsis制作安装程序
                        "arch": [
                            "x64", //64位
                            "ia32" //32位
                        ]
                    }]
                },
                "mac": {
                    // "icon": './public/logo.ico'
                    "hardenedRuntime": true,
                    "gatekeeperAssess": false,
                    "entitlements": "./public/entitlements.mac.plist",
                    "entitlementsInherit": "./public/entitlements.mac.plist"
                },
                linux: {
                    target: ['AppImage'], // 打包格式
                    // category: 'Utility', // Linux 应用程序类别
                    // homepage: "https://www.smartdevice.plus",
                    // email: "dwm716@126.com"
                    // icon: './public/favicon.ico' // Linux 图标文件夹
                }
            }
        }
    },
    configureWebpack: {
        // provide the app's title in webpack's name field, so that
        // it can be accessed in index.html to inject the correct title.
        name: name,
        resolve: {
            alias: {
                '@': resolve('src')
            }
        }
    },
    chainWebpack(config) {
        // set svg-sprite-loader
        config.module
            .rule('svg')
            .exclude.add(resolve('src/icons'))
            .end();
        config.module
            .rule('icons')
            .test(/\.svg$/)
            .include.add(resolve('src/icons'))
            .end()
            .use('svg-sprite-loader')
            .loader('svg-sprite-loader')
            .options({
                symbolId: 'icon-[name]'
            })
            .end();
    }
};
